import Comment from "./comment";

export default class Role {
  constructor(width = Comment.roleWidth, height = Comment.roleHeight) {
    this.width = width;
    this.height = height;
  }
  create(x, y, name) {
    // 创建一个角色  x , y 是坐标  name  是代表玩家
    let _R = document.createElement("img");
    _R.src = require(`@/assets/${name}.gif`);
    _R.className = name;
    _R.style.width = this.width + "px";
    _R.style.height = this.height + "px";
    _R.style.position = "absolute";
    // 服务器返回的坐标是用人物中心点来计算的  这里减去人物一半距离  得到人物左上角position值
    _R.style.top = y - this.width / 2 + "px";
    _R.style.left = x - this.width / 2 + "px";
    _R.style.zIndex = "2";
    document.getElementById("box").appendChild(_R);
  }
  move(r, l, t) {
    // 通过服务器告诉我  其他玩家走了多少
    r.style.top = t - this.width / 2 + "px";
    r.style.left = l - this.width / 2 + "px";
  }
  remove(r) {
    document.getElementById("box").removeChild(r);
  }
}
